package com.gitee.huanminabc.fastboot.context;

import com.alibaba.fastjson.JSONObject;
import com.gitee.huanminabc.jcommon.test.TaskTimeWatch;
import com.gitee.huanminabc.fastboot.annotation.container.Component;
import com.gitee.huanminabc.fastboot.annotation.container.Repository;
import com.gitee.huanminabc.fastboot.annotation.container.RestController;
import com.gitee.huanminabc.fastboot.annotation.container.Service;
import com.gitee.huanminabc.fastboot.event.AppEvent;
import com.gitee.huanminabc.fastboot.event.AppListener;
import com.gitee.huanminabc.fastboot.load.classload.ClassLoadIntercept;
import com.gitee.huanminabc.fastboot.proxy.InterceptorHandle;
import com.gitee.huanminabc.fastboot.load.config.AppBaseInfoConfig;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 简要描述
 *
 * @Author: huanmin
 * @Date: 2025/3/31 23:11
 * @Version: 1.0
 * @Description: 文件作用详细描述....
 */
public class AppContext {

    public static TaskTimeWatch taskTimeWatch = new TaskTimeWatch();
    //容器注解,凡是使用了这些注解的类,都需会被加载到容器中
    public static final Set<Class<? extends Annotation>> CONTAINER_ANNOTATION = new HashSet<>();

    static {
        CONTAINER_ANNOTATION.add(Component.class);
        CONTAINER_ANNOTATION.add(Service.class);
        CONTAINER_ANNOTATION.add(Repository.class);
        CONTAINER_ANNOTATION.add(RestController.class);
    }

    //主类
    public static Class<?> mainClass;

    //配置信息
    public final static JSONObject appConfigMap = new JSONObject();

    public static AppBaseInfoConfig appBaseInfoConfig = new AppBaseInfoConfig();

    public final static Set<String> profiles = new HashSet<>();
    public  static String profile = "dev";


    //项目初始化完成  true 表示完成 false表示未完成
    public volatile static boolean projectLoadOk = false;
    //类加载拦截器
    public final static List<ClassLoadIntercept> classLoadIntercepts = new ArrayList<>();
    //全部的类,系统启动完毕后会全部删除
    public final static Set<Class<?>> allClasses = new HashSet<>();
    //aop拦截器的代理类,系统启动完毕后会全部删除
    public final static List<Class<?>> allAopInterceptorHandleClasses = new ArrayList<>();
    //controller 接口的类,系统启动完毕后会全部删除
    public final static List<Class<?>> allControllerClasses = new ArrayList<>();

    //名称和容器的关系
    public final static Map<String, Object> containerNameAll = new ConcurrentHashMap<>();
    //类和自己的对象
    public final static Map<Class<?>, Object> containerClassAll = new ConcurrentHashMap<>();
    //继承关系
    public final static Map<Class<?>, Map<Class<?>, Object>> containerClassExtendAll = new ConcurrentHashMap<>();
    //接口继承关系
    public final static Map<Class<?>, Map<Class<?>, Object>> containerInterfaceAll = new ConcurrentHashMap<>();


    //监听器(不受容器管理不支持内部依赖注入)
    public final static Map<Class<AppEvent>, List<AppListener<AppEvent>>> appListenerMap = new HashMap<>();
    //类代理处理器(不受容器管理不支持内部依赖注入)
    public final static Map<String, List<InterceptorHandle>> interceptorHandleMap = new HashMap<>();


    //容器初始化的方法回调,系统启动完毕后会全部删除
    public final static List<Method> containerInitMethods = new ArrayList<>();


    //扩展模块加载情况
    public final static Map<String, Boolean> moduleLoadMap = new HashMap<>();

}
